// pages/seller_info/index.js
const app = getApp()
let globalData = getApp().globalData;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentId: '4',
        section: app.globalData.section,
        qian_img: globalData.qian_img,
        good_num: '', //好评量
        receive_num: '', //接待量
        pv_num: '', //浏览量
        aid: '',
        tel: '',
        card_info: {
            head_url: '../../images/seller.jpg',
            logo_url: '../../images/logo.png',
            name: '小明',
            post: '新郑佳兆业悦峰置业顾问',
            tel: '1234566666',
            address: '郑州新郑盘龙山与团结路交叉口西南',
            wechat: '15303897896',
            liulan: '69787',
            yezhu: '9897',
            jiedai: '9898',
            good: '69898',
            intro: '为您选的不是房子，而是幸福的生活'
        },
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (app.globalData.employId && app.globalData.employId != '') {
            this.getData(options.id)
            this.setData({
                pv_num: this.data.pv_num + 1,
                tel: globalData.tel
            });
            this.submitPv(options.id);
            if (options.openid && options.openid != globalData.openid) {
                let data = {
                    aid: options.id,
                    openid: options.openid
                }
                wx.showToast({
                  title: '666',
                })
                globalData.sendPost('adviser/user-source', data).then(res => {

                })
            }
        } else {
            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
            // 所以此处加入 callback 以防止这种情况
            app.employIdCallback = employId => {
                if (employId != '') {
                    this.getData(options.id)
                    this.setData({
                        pv_num: this.data.pv_num + 1,
                        tel: globalData.tel
                    });
                    this.submitPv(options.id);
                    if (options.openid && options.openid != globalData.openid) {
                        let data = {
                            aid: options.id,
                            openid: options.openid
                        }
                        wx.showToast({
                            title: '666',
                          })
                        globalData.sendPost('adviser/user-source', data).then(res => {

                        })
                    }
                }
            }
        }

    },
    //点击每个导航的点击事件
    handleTap: getApp().globalData.handleTap,
    //复制内容
    copyText: function (e) {
        wx.setClipboardData({
            data: e.currentTarget.dataset.text,
            success: function (res) {
                wx.getClipboardData({
                    success: function (res) {
                        wx.showToast({
                            title: '复制成功'
                        })
                    }
                })
            }
        })
    },
    //电话咨询
    telClick(e) {
        let tel = e.currentTarget.dataset.tel;
        wx.makePhoneCall({
            phoneNumber: tel,
        });
        this.setData({
            receive_num: this.data.receive_num + 1,
        });
        this.submitReceive();
    },
    //了解项目
    bindKnow: function () {
        wx.navigateTo({
            url: '../index/index',
        })
    },
    //线上认购
    bindPayplan: function () {
        wx.navigateTo({
            url: '../payPlan/index',
        })
    },
    //预约接待
    toyuyue: function () {
        var id = this.data.card_info.id;
        var head_img = this.data.card_info.head_img;
        var name = this.data.card_info.name;
        var tel = this.data.card_info.mobile;
        var seller_sel = true;
        this.setData({
            receive_num: this.data.receive_num + 1,
        });
        this.submitReceive();
        wx.navigateTo({
            url: '../yuyue/index?id=' + id + '&head_img=' + head_img + '&name=' + name + '&seller_sel=' + seller_sel + '&tel=' + tel,
        })
    },
    //提示未开发此功能
    totishi: function () {
        globalData.showHint('暂未开启');
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target)
        }
        return {
            title: '置业顾问名片',
            path: '/pages/seller_info?id=' + this.card_info.aid + '&openid=123456'
        }
    },
    getData(id) {
        let data = {
            aid: id ? id : 1
        }
        globalData.sendPost('adviser/detail', data).then(res => {
            if (res.status == 1) {
                let data = res.adviser;
                data['num'] = res.data;
                this.setData({
                    card_info: data,
                    pv_num: data.num.pv,
                    good_num: data.num.good,
                    receive_num: data.num.receive,
                    aid: data.num.aid
                })
            }
        })
    },
    //接待量
    submitReceive() {
        let data = {
            aid: this.data.aid
        }
        globalData.sendPost('adviser/add-receive', data).then(res => {})
    },
    //浏览量
    submitPv(id) {
        let data = {
            aid: id ? id : 1
        }
        globalData.sendPost('adviser/add-pv', data).then(res => {})
    },
    startmessage() {
        console.log('请求企业微信')
    },
    completemessage(res) {
        if (res.detail.errcode == "-3002") {
            globalData.showHint('获取插件配置信息失败');
        } else if (res.detail.errcode == "-3004") {
            globalData.showHint('用户信息授权失败');
        } else if (res.detail.errcode == "-3005") {
            globalData.showHint('客服消息发送失败');
        } else if (res.detail.errcode == "-3006") {
            globalData.showHint('当前客服人员与您是好友关系');
        } else if (res.detail.errcode == "-3008") {
            globalData.showHint('当前配置没有客服人员');
        } else {
            globalData.showHint('请查看服务通知的邀请');
        }
    },
    cancleFocus() {},
    getPhoneNumber(e) {
        if (e.detail.errMsg == "getPhoneNumber:ok") {
            let data = {
                openid: globalData.openid,
                encryptedData: e.detail.encryptedData,
                iv: e.detail.iv,
                pid: globalData.pid
            }
            globalData.sendPost('wxuser/update-wxuser', data).then(res => {
                globalData.tel = res.wxuser.phone;
                wx.makePhoneCall({
                    phoneNumber: res.wxuser.phone,
                })
            })
        } else {
            console.log('没有获取电话权限');
        }
    }
})